home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap04 / AutomaticDoor.wrl < prev    next >
Text File  |  1996-10-14  |  4KB  |  139 lines

  1. #VRML V2.0 utf8
  2.  
  3. #
  4. # automatic door
  5. # when the light is turned on, the door opens / closes automatically.
  6. #
  7.  
  8. # turn off the headlight
  9. NavigationInfo{
  10.         headlight FALSE
  11. }
  12.  
  13. # initial viewpoint
  14. Viewpoint{
  15.         position 0 2 5
  16. }
  17.  
  18. # room
  19. Shape{
  20.         geometry IndexedFaceSet{
  21.                 solid FALSE             # double face
  22.                 coord Coordinate{
  23.                         point[    2 0 -10,              #0
  24.                                  10 0 -10,              #1
  25.                                  10 0  10,              #2
  26.                                 -10 0  10,              #3
  27.                                 -10 0 -10,              #4
  28.                                  -2 0 -10,              #5
  29.                                   2 3 -10,              #6
  30.                                  10 3 -10,              #7
  31.                                  10 3  10,              #8
  32.                                 -10 3  10,              #9
  33.                                 -10 3 -10,              #10
  34.                                  -2 3 -10               #11
  35.                         ]
  36.                 }
  37.                 coordIndex[     6, 0, 1, 7, -1,         #0
  38.                                 7, 1, 2, 8, -1,         #1
  39.                                 8, 2, 3, 9, -1,         #2
  40.                                 9, 3, 4, 10, -1,        #3
  41.                                 10, 4, 5, 11, -1,       #4
  42.                                 4, 3, 2, 1              #5 (floor)
  43.                 ]
  44.                 color Color{
  45.                         color[  1 1 0,          #0 (wall)
  46.                                 0 0.2 1.0       #1 (floor)
  47.                         ]
  48.                 }
  49.                 colorPerVertex FALSE
  50.                 colorIndex[     0, 0, 0, 0, 0, 1]
  51.         }
  52. }
  53.  
  54.  
  55. DEF LIGHT1 DirectionalLight{
  56.         on FALSE
  57. }
  58.  
  59. DEF LIGHT2 DirectionalLight{
  60.         direction 0 0 1
  61.         on FALSE
  62. }
  63.  
  64. Transform{
  65.         translation 0 4 0
  66.         children[
  67.         # lamp shade
  68.         DEF LAMP_SHADE Shape{
  69.                 geometry Cone{
  70.                         height 2
  71.                         bottomRadius 2
  72.                 }
  73.         },
  74.         # sensor to turn the light on / off
  75.         DEF LIGHT_ON_SWITCH TouchSensor{}
  76.         ]
  77. }
  78.  
  79. Transform{
  80.         translation 0 1.5 -10.1
  81.         children[
  82.         # door
  83.         DEF DOOR Transform{
  84.                 children[
  85.                 Shape{geometry Box{size 4 3 0.1}}
  86.                 ]
  87.         },
  88.         DEF PROX_SENSOR ProximitySensor{
  89.                 size 8 3 15
  90.         }
  91.         ]
  92. }
  93.  
  94. DEF DOOR_OPEN_TIME TimeSensor{
  95.         cycleInterval 2
  96. }
  97.  
  98. DEF DOOR_OPEN_INTP PositionInterpolator{
  99.         key [ 0, 1]
  100.         keyValue [0 0 0, 3.5 0 0]
  101. }
  102.  
  103. DEF DOOR_CLOSE_TIME TimeSensor{
  104.         cycleInterval 2
  105. }
  106.  
  107. DEF DOOR_CLOSE_INTP PositionInterpolator{
  108.         key [ 0, 1]
  109.         keyValue [3.5 0 0, 0 0 0]
  110. }
  111.  
  112. DEF DOOR_SCRIPT Script{
  113.         url "AutomaticDoor.class"
  114.  
  115.         # light control
  116.         eventIn SFTime touched
  117.         eventOut SFBool turnOnLight
  118.  
  119.         # door control
  120.         eventIn SFTime enterArea
  121.         eventOut SFTime openDoor
  122.         eventIn SFTime exitArea
  123.         eventOut SFTime closeDoor
  124. }
  125.  
  126. ROUTE LIGHT_ON_SWITCH.touchTime TO DOOR_SCRIPT.touched
  127. ROUTE DOOR_SCRIPT.turnOnLight TO LIGHT1.on
  128. ROUTE DOOR_SCRIPT.turnOnLight TO LIGHT2.on
  129.  
  130. ROUTE PROX_SENSOR.enterTime TO DOOR_SCRIPT.enterArea
  131. ROUTE DOOR_SCRIPT.openDoor TO DOOR_OPEN_TIME.set_startTime
  132. ROUTE DOOR_OPEN_TIME.fraction_changed TO DOOR_OPEN_INTP.set_fraction
  133. ROUTE DOOR_OPEN_INTP.value_changed TO DOOR.set_translation
  134.  
  135. ROUTE PROX_SENSOR.exitTime TO DOOR_SCRIPT.exitArea
  136. ROUTE DOOR_SCRIPT.closeDoor TO DOOR_CLOSE_TIME.set_startTime
  137. ROUTE DOOR_CLOSE_TIME.fraction_changed TO DOOR_CLOSE_INTP.set_fraction
  138. ROUTE DOOR_CLOSE_INTP.value_changed TO DOOR.set_translation
  139.